<template>
	
	<div>
		<van-form @submit="onSubmit">
		  <van-field
		    v-model="nickname"
		    name="nickname"
		    label="用户名"
		    placeholder="请输入用户名或邮箱"
		  />
		  <van-field
		    v-model="password"
		    type="password"
		    name="password"
		    label="密码"
		    placeholder="密码"
		  />
		  <div style="margin: 16px;">
		    <van-button round block type="info" native-type="submit" >
		      登录
		    </van-button>
			
		  </div>
		</van-form>
		<van-button round block type="info" to="register">
		  注册跳转
		</van-button>
	</div>
	
</template>

<script>
	import { Toast } from 'mint-ui';
export default{
	data(){
		return{
			xinxi:[],
			nickname: '',
			password: ''
		}
	},
	methods:{
		onSubmit(values) {
		      console.log('submit', values);
			  this.$http.post('http://127.0.0.1:8080/login',values,{ emulateJSON: true }).then(result => {
				  if(result.body.err_code === 0){
					  sessionStorage.setItem('member',JSON.stringify(result.body.message.user))
					  // 调用vuex中mutations的方法
					  this.$store.commit('loginUser')
					  Toast(result.body.message.toast)
					  console.log(sessionStorage.getItem('member'))
					  this.$store.commit('updateUserId')
					  // window.location.reload()
					  this.$router.push({path:'/'})
				  }else{
					  Toast(result.body.message)
				  }
			  })
		    }
	}
}
</script>

<style lang="scss" scoped></style>
